<!--boostrap modal -->
<div class="modal fade bs-example-modal-sm" tabindex="-1" id="myModal" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content" style="z-index: 1050">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">菜单类别管理</h4>
        </div>
        <div class="modal-body">
            <form class="form-edit" id="form-edit">
                <div class="input-group">
                    <div class="input-group-addon">编号</div>
                    <input type="text" class="form-control" name="code" value="{$data.code}" id="code" placeholder="类别编号"/>
                </div>
                <div class="input-group">
                    <div class="input-group-addon">名称</div>
                    <input type="text" class="form-control" name="name" value="{$data.name}" id="name" placeholder="类别名称"/>
                </div>
                <div class="input-group">
                    <div class="input-group-addon">排序</div>
                    <input type="number" class="form-control" name="sort" value="{$data.sort}" value="0" id="sort" placeholder="排序顺序"/>
                </div>
                <div class="input-group">
                    <div class="input-group-addon">状态</div>
                    <div class="input-status">
                        <label class="radio-inline">
                            <input type="radio" class="statue" <?php if(empty($data) || $data['status']==1) echo "checked='checked'"?> name="status" id="status1" value="1"/>启用                            
                        </label>
                        <label class="radio-inline">
                            <input type="radio"  class="statue" <?php if(!empty($data) && $data['status']==0) echo "checked='checked'"?> name="status" id="status0" value="0" />停用
                        </label>
                    </div>
                </div>
                <div class="input-group">
                    <div class="input-group-addon">图标</div>
                    <input class="form-control" name="icon" value="{$data.icon}" id="icon" placeholder="图标"/>
                </div>
                <input type="hidden" name="id" value="{$data.id}" id="modal-id"/>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" id="btn-save" class="btn btn-primary">保存</button>
        </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
    $("#btn-save").click(function(){
        if(!check()){
            return;
        }
        $.ajax({
            url:"__URL__/save",
            data:$("#form-edit").serialize(),
            type:"post",
            dataType:"json",
            success:function(data){
                alert(data.info);                
                if(data.code==1){
                    window.location.reload();
                }
            }
        });
    });

    function check(){
        var code = $("#code").val().trim();
        var name = $("#name").val().trim();
        var sort = $("#sort").val().trim();
        var icon = $("#icon").val().trim();
        if(code==""){
            alert("请输入编号");
            return false;
        }
        if(name==""){
            alert("请输入编名称");
            return false;
        }
        if(sort==""){
            alert("请输入排序顺序");
            return false;
        }
        if(isNaN(sort)){
            alert("排序顺序必须是数字!");
            return false;
        }
        if(icon==""){
            alert("请输入图标");
            return false;
        }
        return true;
    }
</script>